//
//  newsViewController.m
//  网易新闻
//
//  Created by mac on 16/7/21.
//  Copyright © 2016年 xbk. All rights reserved.
//

#import "newsViewController.h"
#import "newsModel.h"
#import "newsTableViewCell.h"

@interface newsViewController ()

@property (nonatomic,strong) NSArray *dataArr;

@end

@implementation newsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}


-(void)setUrlStr:(NSString *)urlStr{
    
    NSLog(@"%@",urlStr);
    
    //向newsModel传值
    [newsModel downloadWithUrl:urlStr successBlock:^(NSArray *arr) {
        
        //NSLog(@"%@",arr);
        self.dataArr = arr;
        
        [self.tableView reloadData];
        
    } failBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return  self.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    newsModel *model = self.dataArr[indexPath.row];
    
    NSString *Identifier;
    
    if (model.imgType) {
        
        Identifier = @"BigCell";
    }else if (model.imgextra.count == 2){
    
        Identifier = @"imagesCell";
    }
    else{
    
        Identifier = @"BaseCell";
    }
    
    newsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier forIndexPath:indexPath];
    
    //cell.textLabel.text = model.title;
    cell.model = model;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    newsModel *model = self.dataArr[indexPath.row];
    
    if (model.imgType) {
        
        return 200;
    }else if (model.imgextra.count == 2){
    
        return 120;
    }
    else{
    
        return 80;
    }
}


@end
